<?php
/**
 * ooPHP - object oriented PHP framework
 * @author Kamil Mikolajczyk ( rego (at) gazeta (dot) pl )
 * @version 1.0
 *
 */

/**
 * 
 * @author Kamil Mikolajczyk ( rego (at) gazeta (dot) pl )
 * @version 1.0
 *
 */
 class Layout
 {
 	var $divs = Array();
 	
 	var $templateString = null;
 	
 	function Layout($path = null)
 	{
 		if($path)
 		{
			try{
				$this -> loadFile($path);
			} catch (Exception $e) {
				throw $e;
			}
 		}
 	}
 	
 	function loadFile($path)
 	{
 		$this -> templateString = file_get_contents($path);
		if(!$this -> templateString || $this -> templateString == "")
			throw new Exception("Layout::loadFile() - file not loaded");
 	}
 	
 	function addDiv($key, $div)
 	{
 		$this -> divs[$key] = $div;
 	}
 	
 	function render($indents = 0)
 	{
		$temp = explode("%%%", $this -> templateString);
		$templateArray = Array();
		
		foreach($temp as $k => $v)
		{
			if($k%2==1)
				$templateArray[$v] = $divs[$v]; 
			else
				$templateArray[] = $v;
		}
		
		foreach($templateArray as $e)
		{
			echo $e;
		}	
 	}
 }
 ?>